$(function () {
    $("#jqGrid").jqGrid({
        url: baseURL + 'sys/currentCount/list',
        datatype: "json",
        colModel: [
            {label: '流水id', name: 'accountId', width: 90, key: true,align:"center"},
            {label: '姓名', name: 'username', width: 75,align:"center"},
            {label: '手机号码', name: 'phone', sortable: false, width: 75,align:"center"},
            {label: '收入/支出', name: 'income', width: 85,align:"center"},
            {label: '流水类型', name: 'incomeName', width: 60,align:"center"},
            {label: '金额', name: 'amount',  width: 45,formatter:function (value,options,row) {
                    return value.toFixed(2);
                },align:"center"},
            {label: '创建时间', name: 'createDate', width: 90,align:"center"}
        ],
        viewrecords: true,
        height: 385,
        rowNum: 10,
        rowList: [10, 30, 50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth: true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader: {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },
        gridComplete: function () {
            //隐藏grid底部滚动条
            $("#jqGrid").closest(".ui-jqgrid-bdiv").css({"overflow-x": "hidden"});
        }
    });

    vm.BindType();

});


var vm = new Vue({
    el: '#rrapp',
    data: {
        q: {
            startTime:null,
            endTime:null,
            username: null,
            phone: null,
            incomeType: 0
        },
        showList: true,
        title: null,
        roleList: {},
        user: {
            status: 1,
            deptId: null,
            deptName: null,
            roleIdList: []
        },
        incomeTypes: [],

    },
    methods: {
        query: function () {
            vm.reload();
        },
        add: function () {
            vm.showList = false;
            vm.title = "新增";

        },

        update: function () {
            var userId = getSelectedRow();
            if (userId == null) {
                return;
            }

            vm.showList = false;
            vm.title = "修改";

        },
        reload: function () {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {'username': vm.q.username,'phone':vm.q.phone,'incomeType':vm.q.incomeType,'startTime':vm.q.startTime,'endtTime':vm.q.endtTime},
                page: page
            }).trigger("reloadGrid");
        },
        BindType:function () {
            $.get(baseURL+"sys/currentCount/incomeType",r=>{
                vm.$set(vm.incomeTypes, 0, {
                    incomeType: 0,
                    incomeName: "请选择类型"
                });
                for (var i = 0; i < r.list.length; i++) {
                    vm.$set(vm.incomeTypes, (i + 1), r.list[i]);
                }


            })
        }
       
    }
});